package com.kkb.kkbcommon.annotation.validation.validator;

import com.kkb.kkbcommon.annotation.validation.annotation.PhoneNumber;
import com.kkb.kkbcommon.basic.*;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Author: 朱明亮
 * @Description: 手机号码校验器
 * @Data Created in 2021-08-20 14:51:36
 * @Modified by:
 */
public class PhoneNumberValidator implements ConstraintValidator<PhoneNumber, String> {

    @Override
    public void initialize(PhoneNumber constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return BaseUtil.haveEmpty(value) ? true : RegexUtil.isMatchByRegex(
                value,
                "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");
    }
}
